package com.sample.rx3.app;

import android.app.Application;
import android.text.TextUtils;

import com.loyal.rx3.RxUtil;

import java.io.File;

public class Rx3App extends Application {
    private static Rx3App instance;
    private String packagePath;

    public static Rx3App getInstance() {
        return instance;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
        RxUtil.errorHandler();
        getPkgDirPath();
    }

    /**
     * 程序主目录
     */
    private void getPkgDirPath() {
        File pkgFile = getExternalFilesDir("");
        if (null == pkgFile) {
            packagePath = "";
            return;
        }
        packagePath = pkgFile.getPath();
        packagePath = TextUtils.isEmpty(packagePath) ? "" : packagePath;
        if (!packagePath.endsWith("/")) {
            packagePath = String.format("%s/", packagePath);
        }
    }

    public String getPackagePath() {
        return packagePath;
    }
}
